
//2905.找出满足差值条件的下标II
class Solution {
public:
    vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {
        //枚举右,维护左
        //根据abs(i-j)>=indexDiffer,维护与当前位置相差indexDiffer个单位长度位置的左边数据
        int n=nums.size();
        if(indexDifference>=n) return {-1,-1};  //数组长度不够直接返回

        pair<int,int> prev_min={INT_MAX,-1},prev_max={INT_MIN,-1};  //存储左边的最大值和最小值

        for(int i=indexDifference;i<n;i++)
        {
            int inser=i-indexDifference;
            if(nums[inser]<prev_min.first) prev_min={nums[inser],inser};
            if(nums[inser]>prev_max.first) prev_max={nums[inser],inser};   //更新最大值和最小值

            if(abs(prev_max.first-nums[i])>=valueDifference) return {prev_max.second,i};  //判断左边是否存在满足条件的数据
            if(abs(prev_min.first-nums[i])>=valueDifference) return {prev_min.second,i};
        }
        return {-1,-1};
    }
};